package week04.homework01MazeGame.utils;

import week04.homework01MazeGame.model.item.Equipment;
import week04.homework01MazeGame.model.item.potion.BasePotion;
import week04.homework01MazeGame.model.item.potion.PotionFactory;
import week04.homework01MazeGame.settings.MonsterGrowth;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author li
 */
public class RandomGenerator {

    private static final Random RANDOM = new Random();

    public static BasePotion randomGeneratePotion() {
        String[] potions = PotionFactory.getPotionNames();
        return PotionFactory.getPotion(potions[RANDOM.nextInt(potions.length)]);
    }

    public static Equipment randomGenerateEquipment() {
        List<Equipment> equipments = new ArrayList<>(
                List.of(
                        new Equipment("长剑", 10, 0),
                        new Equipment("长剑", 10, 0),
                        new Equipment("世纪之剑", 100, 0)
                )
        );
        return equipments.get(RANDOM.nextInt(equipments.size()));
    }

    /**
     * 怪物级别生成概率
     * 1. 幼年怪物 50%
     * 2. 成年怪物 30%
     * 3. 精英怪物 15%
     * 4. Boss 5%
     */
    private static final double JUVENILE_PROBABILITY = 0.5;

    private static final double ADULT_PROBABILITY = 0.3;

    private static final double ELITE_PROBABILITY = 0.15;

    private static final double BOSS_PROBABILITY = 0.05;

    public static MonsterGrowth randomGenerateMonsterGrowth() {
        double probability = RANDOM.nextDouble();
        if (probability <= JUVENILE_PROBABILITY) {
            return MonsterGrowth.JUVENILE;
        } else if (probability <= JUVENILE_PROBABILITY + ADULT_PROBABILITY) {
            return MonsterGrowth.ADULT;
        } else if (probability <= JUVENILE_PROBABILITY + ADULT_PROBABILITY + ELITE_PROBABILITY) {
            return MonsterGrowth.ELITE;
        } else {
            return MonsterGrowth.BOSS;
        }
    }

}
